<include file="Public:header" />

<!--<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>-->

<script type="text/javascript">

    var d = {$jsApiParameters | default = ''};

    if (!d) {

        d = {};

        alert("jsApiParameters初始化错误");
    }

    //调用微信JSapi支付
    function jsApiCall()
    {
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest', d,
                function (res) {
                    WeixinJSBridge.log(res.err_msg);

                    switch (res.err_msg) {
                        case 'get_brand_wcpay_request:cancel':
                            alert("您取消了支付");
                            break;
                        case 'get_brand_wcpay_request:fail':
                            alert("支付失败");
                            break;
                        case 'get_brand_wcpay_request:ok':
                            alert("支付成功");                            
                            window.location.href = "{:U('Member/order')}";
                            break;
                    }
                }
        );
    }

    function callpay()
    {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }

</script>

<style>
    button {
        position:fixed; 
        max-width: 620px;
        width:100%; 
        height:40px; 
        bottom: 55px; 
        text-align: center; 
        background: #FE6714 none repeat scroll 0 0; 
        padding: 10px 0;
        height: 40px;
        color:white;
        border:0px #FE6714 solid;
        border-radius: 6px;
        font-size:16px;
    }

    .form-group {color:#fff;}

    #main{background: #EFEFEF}
</style>

<div id="main">

    <include file="Public:procat" />

    <div class="goodslist" style="padding:0 5px;">

        <div class="jiezhi" style="text-align: center; border: 1px solid #eaeaea;background: #fff">
            <p style="padding:30px 0px; font-size:18px;">

                <span>

                    <img src="__PUBLIC__/front/images/pay_index_img/clock.png" />

                    支付截止时间：{$order_info.create_time|date = 'Y-m-d H:i',###}

                </span>

            </p>

        </div>

        <div style="border: 1px solid #eaeaea; margin-top: 20px; padding: 20px 1px 20px 20px; font-size: 16px;background: #fff">

            <p>订单编号：{$order_info.order_no}</p>

            <P>订单金额：{$order_info.total}元</P>

        </div>

    </div>

    <div class="check-box" style="margin: 20px 0; padding: 0 5px;background: #fff">

        <ul style="border: 1px solid #eaeaea;">

            <li style="border-bottom: 1px solid #eaeaea; padding: 10px 20px;">

                <p style="margin: 0;font-size: 18px;">选择支付方式</p>

            </li>

            <li style="overflow: hidden; border-bottom: 1px solid #eaeaea; padding: 8px 20px;">

                <div style="float: left;">

                    <img style="width: 35px;" src="__PUBLIC__/front/images/pay_index_img/wechat.png">

                </div>

                <div style="float: left;padding-left: 15px; ">

                    <h1 style="padding: 0;color: #000000; margin: 0;font-weight: normal;font-size: 14px;">微信支付</h1>

                    <p style="color: #666666;  margin: 0;font-size: 12px;">使用微信支付，方便快捷</p>

                </div>

                <div style="float: right;width:20px; height:20px" class="pay-way" >

                    <input type="radio" name="payfor" value="weixin"  checked style="display: none;"/>

                    <label class="checked" style="background: url(__PUBLIC__/front/images/pay_index_img/pay-bg.gif) no-repeat left bottom; width: 20px;height: 20px; margin-top: 15px; display: block"></label>

                </div>

            </li>	

        </ul>

        <script>

            //支付方式选择
            $(".check-box .pay-way").click(
                    function () {
                        $(this).children('.checked').css("background-position", "left bottom");
                        $(this).parent().siblings().children(".pay-way").children('.checked').css("background-position", "left top");
                        $(this).children("input").attr("checked", "checked");
                        $(this).parent().siblings().children(".pay-way").children('input').removeAttr("checked", "checked");
                    }
            );

            function  toPay() {

                var paytype = '';

                $('input[name="payfor"][checked]').each(function () {
                    paytype = $(this).val();
                });

                if (paytype == 'weixin') {

                    callpay();

                } else if (paytype == 'score') {

                    score();
                }

                return false;
            }


            function score() {

                alert('积分支付');
                return;

                var paymoney = "{$order_info['total']}";

                var balance = "{$balance}";

                var compare = accSub(balance, paymoney);

                if (compare < 0) {

                    jAlert('余额不足', '');
                    return;
                }

                window.location.href = "{:U('Pay/pay_type')}" + '&order_id=' + "{$order_info.id}";

            }

            function accSub(arg1, arg2) {
                return accAdd(arg1, -arg2);
            }

            function accAdd(arg1, arg2) {
                var r1, r2, m;
                try {
                    r1 = arg1.toString().split(".")[1].length;
                } catch (e) {
                    r1 = 0;
                }
                try {
                    r2 = arg2.toString().split(".")[1].length;
                } catch (e) {
                    r2 = 0;
                }
                m = Math.pow(10, Math.max(r1, r2));
                return (arg1 * m + arg2 * m) / m;
            }


        </script>

    </div>

</div>

<div class="form-group">

<button type="button" onclick="callpay()">立即支付</button> 

</div>

<include file="Public:footer" />